//
//  CategoryManager.swift
//  KoiAccounting
//
//  Created by 纪洪文 on 20.03.25.
//

import Foundation
class CategoryManager {
    static let standard = CategoryManager()
    private let categoryDao = KoiAccountingDB.standard.getCategoryDao()
    
    func createDefaultCategorys(uid:String, bookId:String) {
        categoryDao.save(categorys: getDefaultCategoryList(uid: uid, bookId: bookId))
    }
    
    private func getDefaultCategoryList(uid:String, bookId:String) -> Array<AccountingCategory> {
        let date = Date().toISODateString()
        var categoryList = Array<AccountingCategory>()
        let expenseType = CategoryType.expense.rawValue
        let incomeType = CategoryType.income.rawValue
        // 餐饮 -- begin
        categoryList.append(AccountingCategory(cid:"e_meal", name: "餐饮", type: expenseType, icon: "linearicon://koi_rice", orderId: 1, bookId: bookId, uid: uid, createTime: date, updateTime: date))
        categoryList.append(AccountingCategory(cid:"es_meal", name: "三餐", type: expenseType,  icon: "linearicon://koi_rice", orderId: 1, bookId: bookId, uid: uid, parentId: "e_meal", createTime: date, updateTime: date))
        categoryList.append(AccountingCategory(cid:"es_snacks", name: "零食", type: expenseType,  icon: "linearicon://koi_snacks", orderId: 2,bookId: bookId,uid: uid, parentId: "e_meal",createTime: date, updateTime: date))
        categoryList.append(AccountingCategory(cid:"es_fruit", name: "水果", type: expenseType, icon: "linearicon://koi_fruit", orderId: 3,bookId: bookId,uid: uid, parentId: "e_meal",createTime: date, updateTime: date))
        categoryList.append(AccountingCategory(cid:"es_vegetable", name: "蔬菜", type: expenseType, icon: "linearicon://koi_vegetables", orderId: 4,bookId: bookId,uid: uid, parentId: "e_meal",createTime: date, updateTime: date))
        categoryList.append(AccountingCategory(cid:"es_drink", name: "饮品", type: expenseType, icon: "linearicon://koi_soda", orderId: 5,bookId: bookId,uid: uid, parentId: "e_meal",createTime: date, updateTime: date))
        // 餐饮 -- end
        categoryList.append(AccountingCategory(cid:"e_daily",name: "日常", type: expenseType, icon: "linearicon://koi_shopping_bag", orderId: 2, bookId: bookId,uid: uid,createTime: date, updateTime: date))
        categoryList.append(AccountingCategory(cid:"e_traffic",name: "交通", type: expenseType, icon: "linearicon://koi_bus_stop", orderId: 3, bookId: bookId,uid: uid,createTime: date, updateTime: date))
        // 公交 -- begin
        categoryList.append(AccountingCategory(cid:"e_bus",name: "公交", type: expenseType, icon: "linearicon://koi_bus_stop", orderId: 4, bookId: bookId,uid: uid,createTime: date, updateTime: date))
        categoryList.append(AccountingCategory(cid:"es_subway",name: "地铁", type: expenseType, icon: "linearicon://koi_subway", orderId: 1, bookId: bookId,uid: uid, parentId: "e_bus", createTime: date, updateTime: date))
        categoryList.append(AccountingCategory(cid:"es_train",name: "火车", type: expenseType, icon: "linearicon://koi_train", orderId: 2, bookId: bookId,uid: uid, parentId: "e_bus", createTime: date, updateTime: date))
        categoryList.append(AccountingCategory(cid:"es_taxi",name: "出租车", type: expenseType, icon: "linearicon://koi_taxi", orderId: 3, bookId: bookId,uid: uid, parentId: "e_bus", createTime: date, updateTime: date))
        categoryList.append(AccountingCategory(cid:"es_airplane",name: "飞机", type: expenseType, icon: "linearicon://koi_airplane", orderId: 5, bookId: bookId,uid: uid, parentId: "e_bus", createTime: date, updateTime: date))
        categoryList.append(AccountingCategory(cid:"es_car",name: "汽车", type: expenseType, icon: "linearicon://koi_car", orderId: 6, bookId: bookId,uid: uid, parentId: "e_bus", createTime: date, updateTime: date))
        categoryList.append(AccountingCategory(cid:"es_bicycle_sharing",name: "共享单车", type: expenseType, icon: "linearicon://koi_bicycle", orderId: 7, bookId: bookId,uid: uid,  parentId: "e_bus", createTime: date, updateTime: date))
        // 公交 -- end
        categoryList.append(AccountingCategory(cid:"e_entertainment",name: "娱乐", type: expenseType, icon: "linearicon://koi_videogames", orderId: 5, bookId: bookId,uid: uid, createTime: date, updateTime: date))
        categoryList.append(AccountingCategory(cid:"e_phone_call",name: "通讯", type: expenseType, icon: "linearicon://koi_phone_call", orderId: 6, bookId: bookId,uid: uid, createTime: date, updateTime: date))
        categoryList.append(AccountingCategory(cid:"e_costume",name: "服饰", type: expenseType, icon: "linearicon://koi_tshirt", orderId: 7, bookId: bookId,uid: uid,createTime: date, updateTime: date))
        categoryList.append(AccountingCategory(cid:"e_digital",name: "数码", type: expenseType, icon: "linearicon://koi_smartphone", orderId: 8, bookId: bookId,uid: uid,createTime: date, updateTime: date))
        categoryList.append(AccountingCategory(cid:"e_beauty_makeup",name: "美妆", type: expenseType, icon: "linearicon://koi_lipstick", orderId: 9, bookId: bookId,uid: uid,createTime: date, updateTime: date))
        // 住房 -- begin
        categoryList.append(AccountingCategory(cid:"e_cottage",name: "住房", type: expenseType, icon: "linearicon://koi_cottage", orderId: 10, bookId: bookId,uid: uid,createTime: date, updateTime: date))
        categoryList.append(AccountingCategory(cid:"e_rent",name: "房租", type: expenseType, icon: "linearicon://koi_rent", orderId: 1, bookId: bookId,uid: uid, parentId: "e_cottage", createTime: date, updateTime: date))
        categoryList.append(AccountingCategory(cid:"e_loan",name: "房贷", type: expenseType, icon: "linearicon://koi_loan", orderId: 2, bookId: bookId,uid: uid, parentId: "e_cottage", createTime: date, updateTime: date))
        categoryList.append(AccountingCategory(cid:"e_water_charge",name: "水费", type: expenseType, icon: "linearicon://koi_water", orderId: 3, bookId: bookId,uid: uid, parentId: "e_cottage", createTime: date, updateTime: date))
        categoryList.append(AccountingCategory(cid:"e_electric_charge",name: "电费", type: expenseType, icon: "linearicon://koi_flash", orderId: 4, bookId: bookId,uid: uid, parentId: "e_cottage", createTime: date, updateTime: date))
        categoryList.append(AccountingCategory(cid:"e_gas_charge",name: "燃气费", type: expenseType, icon: "linearicon://koi_fire", orderId: 5, bookId: bookId,uid: uid, parentId: "e_cottage", createTime: date, updateTime: date))
        // 住房 -- end
        // 医疗 -- begin
        categoryList.append(AccountingCategory(cid:"e_medical",name: "医疗", type: expenseType, icon: "linearicon://koi_medicine", orderId: 11, bookId: bookId,uid: uid,createTime: date, updateTime: date))
        categoryList.append(AccountingCategory(cid:"es_medicine",name: "药品", type: expenseType, icon: "linearicon://koi_syringe", orderId: 1, bookId: bookId,uid: uid, parentId: "e_medical", createTime: date, updateTime: date))
        categoryList.append(AccountingCategory(cid:"es_cure",name: "治疗", type: expenseType, icon: "linearicon://koi_first_aid_kit", orderId: 2, bookId: bookId,uid: uid, parentId: "e_medical", createTime: date, updateTime: date))
        categoryList.append(AccountingCategory(cid:"es_hospital",name: "住院", type: expenseType, icon: "linearicon://koi_hospital", orderId: 3, bookId: bookId,uid: uid, parentId: "e_medical", createTime: date, updateTime: date))
        categoryList.append(AccountingCategory(cid:"es_medical_examination",name: "体检", type: expenseType, icon: "linearicon://koi_stethoscope", orderId: 4, bookId: bookId,uid: uid, parentId: "e_medical", createTime: date, updateTime: date))
        categoryList.append(AccountingCategory(cid:"es_medical_insurance",name: "保险", type: expenseType, icon: "linearicon://koi_medical_insurance", orderId: 5, bookId: bookId,uid: uid, parentId: "e_medical", createTime: date, updateTime: date))
        // 医疗 -- end
        categoryList.append(AccountingCategory(cid:"e_beer_tobacco",name: "烟酒", type: expenseType, icon: "linearicon://koi_beer_tobacco", orderId: 12, bookId: bookId,uid: uid,createTime: date, updateTime: date))
        categoryList.append(AccountingCategory(cid:"e_car",name: "汽车", type: expenseType, icon: "linearicon://koi_car", orderId: 13, bookId: bookId,uid: uid,createTime: date, updateTime: date))
        categoryList.append(AccountingCategory(cid:"e_travel",name: "旅行", type: expenseType, icon: "linearicon://koi_tickets", orderId: 14, bookId: bookId,uid: uid,createTime: date, updateTime: date))
        categoryList.append(AccountingCategory(cid:"e_social",name: "社交", type: expenseType, icon: "linearicon://koi_social", orderId: 15, bookId: bookId,uid: uid,createTime: date, updateTime: date))
        categoryList.append(AccountingCategory(cid:"e_pet",name: "宠物", type: expenseType, icon: "linearicon://koi_cat", orderId: 16, bookId: bookId,uid: uid,createTime: date, updateTime: date))
        // 学习 -- begin
        categoryList.append(AccountingCategory(cid:"e_study",name: "学习", type: expenseType, icon: "linearicon://koi_book", orderId: 17, bookId: bookId,uid: uid,createTime: date, updateTime: date))
        categoryList.append(AccountingCategory(cid:"es_book",name: "书籍", type: expenseType, icon: "linearicon://koi_book", orderId: 1, bookId: bookId,uid: uid, parentId: "e_study", createTime: date, updateTime: date))
        categoryList.append(AccountingCategory(cid:"es_coach",name: "培训", type: expenseType, icon: "linearicon://koi_coach", orderId: 2, bookId: bookId,uid: uid,  parentId: "e_study", createTime: date, updateTime: date))
        categoryList.append(AccountingCategory(cid:"es_online_learning",name: "网课", type: expenseType, icon: "linearicon://koi_online_learning", orderId: 3, bookId: bookId,uid: uid,  parentId: "e_study", createTime: date, updateTime: date))
        // 学习 -- end
        // 人情 -- start
        categoryList.append(AccountingCategory(cid:"e_worldly",name: "人情", type: expenseType, icon: "linearicon://koi_human_feeling", orderId: 18, bookId: bookId,uid: uid,createTime: date, updateTime: date))
        categoryList.append(AccountingCategory(cid:"es_gift",name: "礼物", type: expenseType, icon: "linearicon://koi_gift", orderId: 1, bookId: bookId,uid: uid, parentId: "e_worldly", createTime: date, updateTime: date))
        categoryList.append(AccountingCategory(cid:"es_envelope",name: "红包", type: expenseType, icon: "linearicon://koi_envelope", orderId: 2, bookId: bookId,uid: uid, parentId: "e_worldly", createTime: date, updateTime: date))
        categoryList.append(AccountingCategory(cid:"es_donate",name: "捐赠", type: expenseType, icon: "linearicon://koi_donate", orderId: 3, bookId: bookId,uid: uid, parentId: "e_worldly", createTime: date, updateTime: date))
        // 人情 -- end
        categoryList.append(AccountingCategory(cid:"e_other",name: "其他", type: expenseType, icon: "linearicon://koi_money", orderId: 19, bookId: bookId,uid: uid,createTime: date, updateTime: date))
        // 收入 -- begin
        categoryList.append(AccountingCategory(cid:"i_salary",name: "工资", type: incomeType, icon: "linearicon://koi_salary", orderId: 1, bookId: bookId,uid: uid,createTime: date, updateTime: date))
        categoryList.append(AccountingCategory(cid:"i_part_time_job",name: "兼职", type: incomeType, icon: "linearicon://koi_payment", orderId: 2, bookId: bookId,uid: uid,createTime: date, updateTime: date))
        categoryList.append(AccountingCategory(cid:"i_bonus",name: "奖金", type: incomeType, icon: "linearicon://koi_bonus", orderId: 3, bookId: bookId,uid: uid,createTime: date, updateTime: date))
        categoryList.append(AccountingCategory(cid:"i_asset_management",name: "理财", type: incomeType, icon: "linearicon://koi_asset_management", orderId: 4, bookId: bookId,uid: uid,createTime: date, updateTime: date))
        categoryList.append(AccountingCategory(cid:"i_envelope",name: "红包", type: incomeType ,icon: "linearicon://koi_envelope", orderId: 5, bookId: bookId,uid: uid,createTime: date, updateTime: date))
        categoryList.append(AccountingCategory(cid:"i_investment",name: "投资", type: incomeType ,icon: "linearicon://koi_investment", orderId: 6, bookId: bookId,uid: uid,createTime: date, updateTime: date))
        categoryList.append(AccountingCategory(cid:"i_house_price",name: "公积金", type: incomeType ,icon: "linearicon://koi_house_price", orderId: 7, bookId: bookId,uid: uid,createTime: date, updateTime: date))
        categoryList.append(AccountingCategory(cid:"i_other",name: "其他", type: incomeType ,icon: "linearicon://koi_money", orderId: 8, bookId: bookId,uid: uid,createTime: date, updateTime: date))
        return categoryList
    }
    
    func clearDefaultCategory(uid:String, bookId:String) {
        categoryDao.deleateAllCategory(uid:uid, bookId:bookId)
    }
}
